import React, { PureComponent } from "react";
import { connect } from "dva";
import { Card } from "antd";
import DataSet from "@antv/data-set";
import Bar from '../../../components/Charts/Bar';




export default class FaultChart extends PureComponent {
  constructor(props) {
    super(props);

  }

  componentDidMount() {

  }



  render() {
    const { chartsData, faultType } = this.props;

    const fields = chartsData.map(e=>faultType[parseInt(e.faultType)-1]);
    const thisMonthlNum = {}, lastMonthlNum={};
    fields.map((item,index)=>{
      thisMonthlNum[item]=chartsData[index].thisMonth
    });
    fields.map((item,index)=>{
      lastMonthlNum[item]=chartsData[index].lastMonth
    });

    // console.log('chartsData',chartsData)

    const data = [
      {
        name: "本月故障发生总数",
        ...thisMonthlNum,
      },
      {
        name: "上月故障发生总数",
        ...lastMonthlNum,
      }
    ];

    const ds = new DataSet();
    const dv = ds.createView().source(data);
    dv.transform({
      type: "fold",
      fields: fields,
      // 展开字段集
      key: "x",
      // key字段
      value: "y" // value字段
    });

    return (

        <Bar
          data={dv}
          height={400}
          type="interval"
        />

    );
  }
}
